﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Serialization;

namespace Helper
{
   public class XMLReader
   {
      private readonly XmlSerializer serializer;
      private FileStream filestream;

      public XMLReader()
      {
         serializer = new XmlSerializer(typeof(List<KukaCoordData>));
      }

      public string readData(string filepath, ref List<KukaCoordData> coords)
      {
         string returns = "";

         filestream = new FileStream(@filepath, FileMode.OpenOrCreate);

         try
         {
            coords = (List<KukaCoordData>)serializer.Deserialize(filestream);

            if (coords.Count == 0)
               returns = "- Warning - XML-Data read but no data in xml-file.";
            else
               returns = "XML-Data read.";
         }
         catch (IOException exception)
         {
            returns = "- Error - " + exception.Message;
         }

         filestream.Close();

         return returns;
      }
   }
}
